/*
 * @Description: 编译配置
 * @version: 1.0.0
 * @Author: Rattenking
 * @Date: 2022-10-18 09:40:46
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-01-06 10:55:28
 */
const path = require("path");
// const { UnifiedWebpackPluginV4 } = require('weapp-tailwindcss/webpack')
const config = {
  projectName: 'taro-react-rui',
  date: '2022-10-18',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: [],
  defineConstants: {
  },
  alias: {
    "@src": path.resolve(__dirname, "..", "src"),
    "@css": path.resolve(__dirname, "..", "src/css"),
    "@com": path.resolve(__dirname, "..", "src/components"),
    "@utils": path.resolve(__dirname, "..", "src/utils"),
  },
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  framework: 'react',
  mini: {
    postcss: {
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      autoprefixer: {
        enable: true,
        config: {}
      },
      pxtransform: {
        enable: true,
        config: {}
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    },
    webpackChain(chain, webpack) {
      // chain.merge({
      //   plugin: {
      //     install: {
      //       plugin: UnifiedWebpackPluginV4,
      //       args: [{
      //         appType: 'taro',
      //         // 下面个配置，会开启 rem -> rpx 的转化
      //         rem2rpx: true
      //       }]
      //     }
      //   }
      // })
    }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    router: {
      mode: 'browser' // 或者是 'hash'
    },
    postcss: {
      tailwindcss: {
        enable: true,
        config: {
          content: [
            './src/**/*.{html,js,jsx,ts,tsx}',
            './src/**/*.scss'
          ],
          watch: true,
          // 添加 JIT 模式配置
          mode: 'jit',
          purge: [
            './src/**/*.{html,js,jsx,ts,tsx}',
            './src/**/*.scss'
          ],
          // 添加热更新相关配置
          hot: true,
          future: {
            removeDeprecatedGapUtilities: true,
            purgeLayersByDefault: true,
          },
          experimental: {
            applyComplexClasses: true,
          },
        }
      },
      autoprefixer: {
        enable: true,
        config: {
        }
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  },
  // 确保开发服务器配置正确
  devServer: {
    hot: true,
    liveReload: true,
    watchFiles: ['./src/**/*'],
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}
